﻿using QLBH.DAO;
using QLBH.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLBH.BLO
{
    class BLO_Phong
    {
        DAO_Phong DAO_p = new DAO_Phong();
        public int Insert(Phong p)
        {
            try
            {
	            DataTable idmax = Connection_Sql.GetDatatable("select max(ma_phong) from Phong", false);
	            int map = 1;
	            if (idmax.Rows[0][0].ToString() == "")
	            {
	                p.Maphong = map.ToString();
	            }
	            else
	            {
	                p.Maphong = (int.Parse(idmax.Rows[0][0].ToString()) + 1).ToString();
	            }
	            return DAO_p.Insert(p);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Lỗi BLO Insert Phong: " + ex.Message);
            }
        }
    }
}
